<template>
  <div>
    <div
      :class="[
        'vue-keyboard-input-wrap',
        '$vue-keyboard-input',
        !allowEnter ? 'vue-keyboard-input-text-one-line-wrap' : '',
        close ? 'vue-keyboard-input-wrap-close ' : '',
      ]"
      :style="inputWrapStyle"
      ref="wrapvueKeyboardInput"
      :currid="inputId"
    >
      <slot name="prepend"></slot>
      <div
        class="vue-keyboard-input-block"
        :style="inputWrapStyle"
        ref="vueKeyboardInputScrollBox"
      >
        <div
          class="vue-keyboard-input"
          :class="[
            disabled ? 'disabled' : '',
            !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
          ]"
          :data-scroll-left="scrollLeft"
          :data-scroll-top="scrollTop"
          @click.stop.prevent="
            allowEnterBoxClickEmptyArea($event, $refs['vueKeyboardInput'])
          "
          ref="vueKeyboardInput"
          tabindex="-1"
        >
          <template v-if="placeholder && value !== 0 && !value">
            <div class="vue-keyboard-input-placeholder">{{ placeholder }}</div>
          </template>

          <div
            tabindex="-1"
            :class="[
              'vue-keyboard-input-text',
              !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
            ]"
            v-html="tmpValue"
            ref="input"
            @click.prevent.stop="getClickElement($event, $refs['input'])"
          ></div>
        </div>
        <!-- 关闭按钮 -->
        <div
          class="
            icon
            iconfont
            icon-round_close_fill_light
            vue-keyboard-input-close
          "
          v-if="value === 0 || value"
          @click.prevent.stop="clear"
        ></div>
      </div>

      <slot name="append"></slot>
    </div>
    <!-- 
    固定键盘上面 -->
    <div v-show="isFocus && showFixedInput">
      <template v-if="allowEnter">
        <div
          :class="[
            'vue-keyboard-input-fixed-wrap',
            'vue-keyboard-input-wrap',
            '$vue-keyboard-input',
            'vue-keyboard-input-block-fixed',
          ]"
          :style="{
            ...fixedInputWrap,
            height: '52px',
            overflow: 'auto',
            display: 'flex',
          }"
          ref="fixedInputWrapBox"
        >
          <div
            :class="[
              !allowEnter ? 'vue-keyboard-input-text-one-line-wrap' : '',
              close ? 'vue-keyboard-input-wrap-close ' : '',
            ]"
            ref="vue-keyboard-input-fixed-wrap"
            :currid="inputId"
            :style="{ height: '40px', flex: 1, overflow: 'auto' }"
          >
            <slot name="prependFixed"></slot>
            <div
              class="vue-keyboard-input-block"
              ref="vueKeyboardInputScrollBoxFixed"
            >
              <div
                class="vue-keyboard-input"
                :class="[
                  disabled ? 'disabled' : '',
                  !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
                ]"
                @click.stop.prevent="
                  allowEnterBoxClickEmptyArea(
                    $event,
                    $refs['vueKeyboardInputFixed']
                  )
                "
                ref="vueKeyboardInputFixed"
                tabindex="-1"
              >
                <template v-if="placeholder && value !== 0 && !value">
                  <div class="vue-keyboard-input-placeholder">
                    {{ placeholder }}
                  </div>
                </template>

                <div
                  tabindex="-1"
                  :class="[
                    'vue-keyboard-input-text',
                    !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
                  ]"
                  v-html="tmpValue"
                  ref="input"
                  @click.prevent.stop="getClickElement"
                ></div>
              </div>
              <!-- 关闭按钮 -->
              <div
                class="
                  icon
                  iconfont
                  icon-round_close_fill_light
                  vue-keyboard-input-close
                "
                v-if="value === 0 || value"
                @click.prevent.stop="clear"
              ></div>
            </div>

            <slot name="appendFixed"></slot>
          </div>
        </div>
      </template>
      <template v-else>
        <div
          :class="[
            'vue-keyboard-input-fixed-wrap',
            'vue-keyboard-input-wrap',
            '$vue-keyboard-input',
            'vue-keyboard-input-block-fixed',
            !allowEnter ? 'vue-keyboard-input-text-one-line-wrap' : '',
            close ? 'vue-keyboard-input-wrap-close ' : '',
          ]"
          ref="vue-keyboard-input-fixed-wrap"
          :currid="inputId"
          :style="{
            ...fixedInputWrap,
          }"
        >
          <slot name="prependFixed"></slot>
          <div
            class="vue-keyboard-input-block"
            ref="vueKeyboardInputScrollBoxFixed"
          >
            <div
              class="vue-keyboard-input"
              :class="[
                disabled ? 'disabled' : '',
                !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
              ]"
              @click.stop.prevent="
                allowEnterBoxClickEmptyArea(
                  $event,
                  $refs['vueKeyboardInputFixed']
                )
              "
              ref="vueKeyboardInputFixed"
              tabindex="-1"
            >
              <template v-if="placeholder && value !== 0 && !value">
                <div class="vue-keyboard-input-placeholder">
                  {{ placeholder }}
                </div>
              </template>

              <div
                tabindex="-1"
                :class="[
                  'vue-keyboard-input-text',
                  !allowEnter ? 'vue-keyboard-input-text-one-line' : '',
                ]"
                v-html="tmpValue"
                ref="input"
                @click.prevent.stop="getClickElement"
              ></div>
            </div>
            <!-- 关闭按钮 -->
            <div
              class="
                icon
                iconfont
                icon-round_close_fill_light
                vue-keyboard-input-close
              "
              v-if="value === 0 || value"
              @click.prevent.stop="clear"
            ></div>
          </div>

          <slot name="appendFixed"></slot>
        </div>
      </template>
    </div>

    <!-- <div
      class="vue-keyboard-input-fixed-wrap"
      :data-scroll-left="scrollLeft"
      :data-scroll-top="scrollTop"
      @click.stop.prevent="focus(true)"
      @touchstart.stop
      v-if="isFocus && showFixedInput"
      ref="vue-keyboard-input-fixed-wrap"
    >
      <slot name="prependFixed"></slot>
      <div
        class="vue-keyboard-input-block vue-keyboard-input-block-fixed"
        :style="fixedInputWrap"
      >
        <div
          class="vue-keyboard-input-fixed"
          v-disabled-body-scroll:[disabledScrollDirectiveStatus]="rotate"
          ref="vueKeyboardInputFixed"
        >
          <template v-if="placeholder && value !== 0 && !value">
            <div class="vue-keyboard-input-placeholder">{{ placeholder }}</div>
          </template>
          <div
            tabindex="-1"
            class="vue-keyboard-input-text"
            v-html="tmpValue"
            ref="input"
            @click.prevent="getClickElement"
          ></div>
          <div
            class="
              icon
              iconfont
              icon-round_close_fill_light
              vue-keyboard-input-close
            "
            v-if="value === 0 || value"
            @click.prevent.stop="clear"
          ></div>
        </div>
      </div>
      <slot name="appendFixed"></slot>
    </div> -->
  </div>
</template>
<script>
import InputMixins from "./mixins/input";
export default {
  name: "defaultInput",
  mixins: [InputMixins],
};
</script>
<style lang="scss">
@import "@/var.scss";
.vue-keyboard-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid #999;
  overflow: auto;
  line-height: 30px;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box; //请勿修改它，否则该节点的scrollHeight计算会把border和padding额外
  -webkit-tap-highlight-color: transparent;
  background: #fff;
  &:focus-visible,
  &:focus,
  &:hover,
  &:active {
    outline: none;
    box-shadow: none;
  }
}
.vue-keyboard-input-block-fixed {
  background: #dedede;
  .vue-keyboard-input-wrap {
    border: none;
    background: #fff;
  }
}
.vue-keyboard-input-block {
  -webkit-tap-highlight-color: transparent;
  padding: 5px;
  width: 100%;
  overflow: auto;
  box-sizing: border-box;
  position: relative;

  flex: 1;
  &:focus-visible,
  &:focus,
  &:hover,
  &:active {
    outline: none;
    box-shadow: none;
  }
  @keyframes flash {
    0% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
  .key-board-flash {
    width: 0px;
    height: 100%;
    min-height: 14px;
    position: relative;
    overflow: visible;
    display: inline-block;
    vertical-align: middle;
    span {
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 1px;
      min-height: 14px;
      height: 100%;
      background: red;
      animation: flash 0.3s infinite linear;
      &:focus-visible,
      &:focus {
        outline: none;
      }
    }
  }
}

.vue-keyboard-input {
  position: relative; //它是必须的，否则会影响获取容器的滚动
  min-height: 30px;
  overflow: auto;
  box-sizing: border-box;
  line-height: 30px;
  flex: 1;
  // padding: 5px;
  word-wrap: break-word;
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;

  &:focus,
  &:hover,
  &:active {
    outline: none;
    box-shadow: none;
  }

  &.disabled {
    background: #eee;
    .vue-keyboard-input-text {
      color: #999;
    }
  }
  .vue-keyboard-text-item {
    display: inline-block;
    vertical-align: middle;
  }
  .vue-keyboard-text-item-empty {
    width: 2px;
    height: 100%;
    min-height: 10px;
  }
  .vue-keyboard-text-item-br {
    display: block;
  }

  .emoji-icon {
    width: 20px;
    height: 20px;
  }
}
.vue-keyboard-input-close {
  position: absolute;
  top: 0;
  right: 5px;
  z-index: 10;
  transition: color 0.2s;
  color: rgba(0, 0, 0, 0.25);
  &:active {
    color: rgba(0, 0, 0, 1);
  }
}
.vue-keyboard-input-text-one-line-wrap {
  .vue-keyboard-input-close {
    top: 50%;
    transform: translateY(-50%);
  }
  &.vue-keyboard-input-wrap-close {
    .vue-keyboard-input-block {
      padding-right: 25px;
      box-sizing: border-box;
    }
  }
}
.vue-keyboard-input-text-one-line {
  position: relative;
  white-space: nowrap !important;
  word-wrap: normal !important;
  z-index: 1;
}
.vue-keyboard-input-text-one-line-close {
  padding-right: 25px;
}
.vue-keyboard-input-text {
  display: inline-block;
  position: relative;
  z-index: 10;
  &:active,
  &:focus-visible,
  &:focus-within,
  &:focus,
  &:hover {
    outline: none;
  }
  &:focus-visible {
    outline: none;
  }
  &.vue-keyboard-input-text-focus {
    background: rgba(135, 206, 235, 0.3);
    &:focus {
      background: rgba(135, 206, 235, 0.3);
    }
  }
}
.vue-keyboard-input-fixed-wrap {
  position: fixed;
  background: $bgColor;
  padding: 5px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  z-index: 9999;
  overflow: hidden;
  border: none !important;
  .emoji-icon {
    width: 20px;
    height: 20px;
  }
  .vue-keyboard-input-block {
    background: #fff;
  }
  .vue-keyboard-input-close {
    right: 10px !important;
  }
}
.vue-keyboard-input-fixed {
  position: relative;
  box-sizing: border-box;
  height: 40px;
  overflow: auto;
  background: #fff;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  .vue-keyboard-input-text {
    flex: 1;
    padding: 5px;
  }
  .confirm-btn {
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    .icon-arrow-right-filling {
      font-size: 22px;
    }
  }
}
.vue-keyboard-input-placeholder {
  color: #999;
  position: absolute;
  z-index: 0;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
}
</style>